"""
Test that when a projection from a volume is registered to the 
volume that it converges to the right solution (best case registration scenario)

"""
import pythonRegistration as pr
from numpy import array
import itk
import ImageCompare

reload(pr)

reg=pr.registration()
reg.verbose = False

fixedFileName = 'C:/Lib/JointTrack/branches/bryan/Images/MovingImage.png'
volFileName = 'C:/Lib/jointtrack/branches/TestData/vert1.vtk'
saveFileName = fixedFileName[:-4]+'_out.png'

reg.SetFixedImageFileName(fixedFileName)
reg.SetVolumeFileName(volFileName)

metric = itk.MeanSquaresImageToImageMetric.IF2IF2.New()
reg.SetImageMetric(metric)

reg.SetWindowNames()

reg.InitializeRegistration()
reg.movingImageInteractor.Disable()

pose = array((0,0,0,0,0,0))
reg.SetPose(pose)
reg.movingImageRenWin.Render()

lowerBounds = array((0,0,0,0,0,0))
upperBounds = array((0,0,0,0,0,0))

maxTime = 1
plotFlag = 0    #don't plot

x_opt, f_opt = reg.DoOptimize('galileo',lowerBounds,upperBounds,maxTime,plotFlag)

reg.SaveMovingImage(saveFileName)

#return 0 if they match, 1 otherwise.
comp = ImageCompare.compare(fixedFileName,saveFileName)

#Test for positive match
assert comp==0

if comp == 0:
    print "Test Success!"
else:
    print "Test Failure!"

